package com.wuliu.controller;

import com.wuliu.common.annotation.NoAuth;
import com.wuliu.common.constant.Constants;
import com.wuliu.common.core.domain.ApiResult;
import com.wuliu.common.utils.StringUtils;
import com.wuliu.system.domain.dto.LoginDto;
import com.wuliu.system.domain.vo.SysAppletUserVo;
import com.wuliu.system.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author realue
 * @version 1.0
 * @date 2023-10-08 12:18
 */
@RestController
@RequestMapping("/app/sys")
@Api(tags = {"登录控制器"})
public class LoginController {

    @Resource
    private LoginService loginService;

    @NoAuth
    @PostMapping("/login")
    @ApiOperation(value = "用户登录", notes = "")
    public ApiResult<SysAppletUserVo> login(@RequestBody @Validated LoginDto loginDto) {
        if (StringUtils.isEmpty(loginDto.getSysAccount())) {
            loginDto.setSysAccount(Constants.DEFAULT_SYSACCOUNT);
        }
        return ApiResult.success(loginService.login(loginDto));
    }

    @NoAuth
    @GetMapping("/sendSms")
    @ApiOperation(value = "发送验证码", notes = "")
    public ApiResult<Boolean> sendSms(String mobile, String sysAccount) {
        return ApiResult.success(loginService.sendSms(mobile, sysAccount));
    }

}
